<script setup lang="ts">
// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 模块导入 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

import { computed, nextTick, reactive, shallowRef, toRefs, watch } from 'vue';
import type { TreeOption } from 'naive-ui';
import dayjs from 'dayjs';
import { useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';
import {
  fetchAddDmRecycleResidual,
  fetchGetDmRecycleResidual,
  fetchGetMyUniqueProvinceCityCounty,
  fetchGetOrgUnitTree,
  fetchUpdateDmRecycleResidual,
  getRecycleOrgInfo
} from '@/service/api';
// import { useDict } from '@/hooks/business/dict';
import { useAuth } from '@/hooks/business/auth';

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 组件名称 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

defineOptions({
  name: 'RecycleResidualOperateModal'
});

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 组合式函数 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

const { validate, restoreValidation } = useNaiveForm();

const { currentOrgPosition, userInfo } = useAuth();

// const { dictOptions } = useDict();

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 父子传参 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

interface Props {
  operateType: OperateType;
  rowData?: Api.Dimo.DmRecycleResidual | null;
}

const props = defineProps<Props>();

interface Emits {
  (e: 'submitted'): void;
}

const emit = defineEmits<Emits>();

const visible = defineModel<boolean>('visible', {
  default: false
});

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架模型 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

export type OperateType = NaiveUI.TableOperateType | 'view';

const isAdd = computed(() => props.operateType === 'add');

const isEdit = computed(() => props.operateType === 'edit');

const isView = computed(() => props.operateType === 'view');

const addKey = computed(() => `DMRECYCLERESIDEAL${userInfo()?.userName}ADD`);

const editKey = computed(() => `DMRECYCLERESIDEAL${userInfo()?.userName}EDIT${props.rowData?.id}`);
const title = computed(() => {
  const titles: Record<OperateType, string> = {
    add: $t('common.add'),
    edit: $t('common.edit'),
    view: '查看'
  };
  return `【${titles[props.operateType]}】农田地膜残留监测点基本情况表`;
});

type Model = Api.Dimo.DmRecycleResidual;

const model: Model = reactive(createDefaultModel());

/**
 * 创建一个默认的模型对象
 *
 * @returns 返回包含默认值的 Model 对象
 */
function createDefaultModel(): Model {
  return {
    id: '',
    createUser: '',
    createTime: '',
    updateUser: '',
    updateTime: '',
    tenantId: '',
    orgId: '',
    positionId: '',
    surveyPointId: '',
    reportDate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
    reportPerson: '',
    reportPersonContactInfo: '',
    investPerson: '',
    investPersonContactInfo: '',
    countyAuthStatus: false,
    countyAuthDate: '',
    countyAuthUserId: 0,
    cityAuthStatus: false,
    cityAuthDate: '',
    cityAuthUserId: 0,
    provinceAuthStatus: false,
    provinceAuthDate: '',
    provinceAuthUserId: 0,
    comment: '',
    totalCultivatedArea: 0,
    sownArea: 0,
    farmhouseName: '',
    contactInfo: '',
    farmhouseType: 1,
    soilTexture: 1,
    averageRainfall: 0,
    sunshineHours: 0,
    frostFreePeriod: 0,
    irrigationMethod: 1,
    cultivatedArea: 0,
    plotLongitude: 0,
    plotLatitude: 0,
    distanceFromHome: 0,
    fieldArea: 0,
    orchardArea: 0,
    protectedArea: 0,
    totalSownArea: 0,
    dmApplyFirstYear: 0,
    dmApplyCoverYears: 0,
    dmApplyCoverMethod: 1,
    dmApplyFilmCycle: 0,
    dmApplyManufacturerName: '',
    dmApplyManufacturerTel: '',
    dmApplyFilmThickness: 0,
    dmApplyFilmWidth: 0,
    dmApplyFilmColor: 1,
    dmRecycleManualArea: 0,
    dmRecycleManualCost: 0,
    dmRecycleMachineArea: 0,
    dmRecycleMachineCost: 0,
    dmRecycleCompoundArea: 0,
    dmRecycleCompoundCost: 0,
    dmRecycleNonRecycleArea: 0,
    dmRecycleResidueAmount: 0,
    dmDisposePile: 0,
    dmDisposeRecycle: 0,
    dmDisposeRural: 0,

    dmDisposeMachine: 0,
    dmDisposeBurn: 0,
    dmDisposeLandfill: 0,
    dmRecycleName: '',
    dmRecyclePrice: 0,
    sampleQuadratOne: 0,
    sampleQuadratTwo: 0,
    sampleQuadratThree: 0,
    sampleQuadratFour: 0,
    sampleQuadratFive: 0,
    township: '',
    village: '',
    provinceCityCountyInfo: {
      provinceId: '',
      provinceName: '',
      cityId: '',
      cityName: '',
      countyId: '',
      countyName: ''
    },
    dmResidualDetails: [createRecyclePilot()],
    orgCode: '',
    seqId: '',
    reportUnit: ''
  };
}

function createRecyclePilot(): Api.Dimo.ResidualCityDirection {
  return {
    residualId: 0,
    cropName: '',
    filmQuantity: 0,
    sowingArea: 0,
    fieldCoverage: 0
  };
}
// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 业务模型 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

const orgTreeOptions = shallowRef<TreeOption[]>([]);

// const showTable = ref<boolean>(true);

const state = reactive({
  farmersList: [
    { value: 1, label: '普通农户' },
    { value: 2, label: '大户' },
    { value: 3, label: '农民专业合作社' }
  ],
  soilTexture: [
    { value: 1, label: '砂土' },
    { value: 2, label: '壤土' },
    { value: 3, label: '粘土' }
  ],
  irrigation: [
    { value: 1, label: '滴灌' },
    { value: 2, label: '沟灌' },
    { value: 3, label: '畦灌' },
    { value: 4, label: '喷灌' },
    { value: 5, label: '无灌溉' }
  ],
  getsoilTexture: new Map([
    [0, ''],
    [1, '砂土'],
    [2, '壤土'],
    [3, '粘土']
  ]),
  getIrrigation: new Map([
    [0, ''],
    [1, '滴灌'],
    [2, '沟灌'],
    [3, '畦灌'],
    [4, '喷灌'],
    [5, '喷灌'],
    [6, '无灌溉']
  ]),
  getFarmersList: new Map([
    [0, ''],
    [1, '普通农户'],
    [2, '种植大户'],
    [3, '农民专业合作社']
  ]),
  getDmApplyFilmColor: new Map([
    [0, ''],
    [1, '白色'],
    [2, '黑色'],
    [3, '其他']
  ])
});

/**
 *  获取用户组织信息
 */
function getUserOrg() {
  getRecycleOrgInfo().then((res) => {
    const { surveyPointId, nextSeqId, orgCode } = res.data;
    model.surveyPointId = surveyPointId;
    model.seqId = nextSeqId;
    model.orgCode = orgCode;
  });
}

const { farmersList, getFarmersList, getDmApplyFilmColor, soilTexture, irrigation, getsoilTexture, getIrrigation } = toRefs(state);

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架方法 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

function handleInitModel() {
  // 首先初始化一个空结构，利于监听事件
  Object.assign(model, createDefaultModel());

  // 初始化我的组织树
  fetchGetOrgUnitTree().then(({ error, data }) => {
    if (!error && data) {
      orgTreeOptions.value = data.map(toTreeOptionNode);
    }
  });

  let localData = null;
  if (props.operateType === 'add') {
    localData = localStorage.getItem(addKey.value);
  } else if (props.operateType === 'edit') {
    localData = localStorage.getItem(editKey.value);
  }

  if (localData) {
    window.$dialog?.info({
      title: $t('common.tip'),
      content: '检测到上次您有未保存的数据，是否继续使用该数据进行操作?',
      positiveText: $t('common.confirm'),
      negativeText: $t('common.cancel'),
      onPositiveClick: () => {
        // showTable.value = false;
        nextTick(() => {
          Object.assign(model, JSON.parse(localData));
          // showTable.value = true;
        });
      },
      onNegativeClick: () => {
        if (isAdd.value) {
          localStorage.removeItem(addKey.value);
        } else if (isEdit.value) {
          localStorage.removeItem(editKey.value);
        }
        handleAEV();
      }
    });
  } else {
    handleAEV();
  }
}

function handleAEV() {
  if (props.operateType === 'add') {
    getUserOrg();
    model.reportPerson = userInfo()?.realName || '';
    fetchGetMyUniqueProvinceCityCounty().then(({ error, data }) => {
      if (!error && data) {
        model.provinceCityCountyInfo = data;
        model.orgId = data.countyId ?? data.cityId ?? data.provinceId;
      }
    });
  } else if (['edit', 'view'].includes(props.operateType) && props.rowData) {
    // showTable.value = false;
    fetchGetDmRecycleResidual(props.rowData?.id || '').then(({ error, data }) => {
      if (!error && data) {
        data.reportDate = dayjs(data.reportDate).format('YYYY-MM-DD HH:mm:ss');
        Object.assign(model, data);
        // showTable.value = true;
      }
    });
  }
}

function closeModal() {
  visible.value = false;
}

async function handleSubmit() {
  await validate();
  const func = isAdd.value ? fetchAddDmRecycleResidual : fetchUpdateDmRecycleResidual;
  if (isAdd.value) {
    model.orgId = currentOrgPosition()?.orgId || '';
    model.positionId = currentOrgPosition()?.positionId || '';
  }
  const { error, data } = await func(model);
  if (!error && data) {
    window.$message?.success(isAdd.value ? $t('common.addSuccess') : $t('common.updateSuccess'));
    if (isAdd.value) {
      localStorage.removeItem(addKey.value);
    } else if (isEdit.value) {
      localStorage.removeItem(editKey.value);
    }
    closeModal();
    emit('submitted');
  }
}

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 业务方法 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

function toTreeOptionNode(item: Api.SystemManage.OrgUnitTree): TreeOption {
  const option: TreeOption = {
    key: item.id,
    label: item.name,
    disabled: item.orgType !== 'County'
  };
  if (item.children && item.children.length > 0) {
    option.children = item.children.map(toTreeOptionNode);
  }
  return option;
}

function plusPilot(index: number) {
  if (model.dmResidualDetails.length === index + 1) {
    model.dmResidualDetails.push(createRecyclePilot());
  } else {
    model.dmResidualDetails.splice(index + 1, 0, createRecyclePilot());
  }
}

function reducePilot(index: number) {
  model.dmResidualDetails.splice(index, 1);
}

/** 表格滚动事件 */

function tempSave() {
  if (isAdd.value) {
    localStorage.removeItem(addKey.value);
    const plainObject = JSON.parse(JSON.stringify(model));
    localStorage.setItem(addKey.value, JSON.stringify(plainObject));
  } else if (isEdit.value) {
    const plainObject = JSON.parse(JSON.stringify(model));
    localStorage.setItem(editKey.value, JSON.stringify(plainObject));
  }
  window.$message?.success('临时保存成功');
}

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架生命周期 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

watch(visible, () => {
  if (visible.value) {
    handleInitModel();
    restoreValidation();
  }
});

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 业务生命周期 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

// ---------- 页面统计 ----------
</script>

<template>
  <NModal v-model:show="visible" :title="title" preset="card" class="w-1280px" :close-on-esc="false" :mask-closable="false">
    <div class="info">
      <div class="title-info">
        <NSpace v-if="!isView">
          <div class="w-300px">
            <NInput v-model:value="model.surveyPointId" type="text" disabled>
              <template #prefix>调查点编号：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.provinceCityCountyInfo.cityName" type="text" disabled>
              <template #prefix>市（州）：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.provinceCityCountyInfo.countyName" type="text" disabled>
              <template #prefix>县（市、区）：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.township" type="text">
              <template #prefix>乡（镇）：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.village" type="text">
              <template #prefix>村：</template>
            </NInput>
          </div>
        </NSpace>
        <NSpace v-else>
          <span class="mr-60px">
            <b>填报单位：</b>
            {{ model.surveyPointId }}
          </span>
          <span class="mr-60px">
            <b>市：</b>
            {{ model.provinceCityCountyInfo.cityName }}
          </span>
          <span class="mr-60px">
            <b>县：</b>
            {{ model.provinceCityCountyInfo.countyName }}
          </span>
          <span class="mr-60px">
            <b>镇（乡）：</b>
            {{ model.township }}
          </span>
          <span class="mr-60px">
            <b>村：</b>
            {{ model.village }}
          </span>
          <span>
            <b>填报日期：</b>
            {{ dayjs(model.reportDate).format('YYYY-MM-DD') }}
          </span>
        </NSpace>
      </div>
      <div class="table-info">
        <table>
          <thead>
            <tr>
              <th colspan="5">指标名称</th>
              <th class="w-80px text-center">单位</th>
              <th class="w-200px">指标值</th>
            </tr>
          </thead>
          <tbody>
            <!-- 基本情况 -->
            <tr>
              <td rowspan="15">农业基本生产信息</td>
              <td colspan="4">农户姓名</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NInput v-model:value="model.farmhouseName" type="text" size="small" />
              </td>
              <td v-else class="text-right">{{ model.farmhouseName }}</td>
            </tr>
            <tr>
              <td colspan="4">联系方式</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NInput v-model:value="model.contactInfo" type="text" size="small" />
              </td>
              <td v-else class="text-right">{{ model.contactInfo }}</td>
            </tr>
            <tr>
              <td colspan="4">农户类型</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NRadioGroup v-model:value="model.farmhouseType">
                  <NRadio v-for="item in farmersList" :key="item.value" :value="item.value" :label="item.label" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ getFarmersList.get(model.farmhouseType) }}</td>
            </tr>
            <tr>
              <td rowspan="2">地块中心经纬度</td>
              <td colspan="3" class="text-center">经度</td>
              <td class="text-center">°</td>

              <td v-if="!isView">
                <NInputNumber v-model:value="model.plotLongitude" clearable :precision="6" size="small" />
              </td>
              <td v-else class="text-right">{{ model.plotLongitude }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">纬度</td>
              <td class="text-center">°</td>

              <td v-if="!isView">
                <NInputNumber v-model:value="model.plotLatitude" clearable :precision="6" size="small" />
              </td>
              <td v-else class="text-right">{{ model.plotLatitude }}</td>
            </tr>
            <tr>
              <td colspan="4">地块与住处距离</td>
              <td class="text-center">公里</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.distanceFromHome" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.distanceFromHome }}</td>
            </tr>
            <tr>
              <td rowspan="3">耕地面积</td>
              <td colspan="3" class="text-center">大田</td>
              <td class="text-center">亩</td>

              <td v-if="!isView">
                <NInputNumber v-model:value="model.fieldArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.fieldArea }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">园地</td>
              <td class="text-center">亩</td>

              <td v-if="!isView">
                <NInputNumber v-model:value="model.orchardArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.orchardArea }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">保护地</td>
              <td class="text-center">亩</td>

              <td v-if="!isView">
                <NInputNumber v-model:value="model.protectedArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.protectedArea }}</td>
            </tr>
            <tr>
              <td colspan="4">农作物播种面积</td>
              <!-- <td colspan="2">亩</td> -->
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.totalSownArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.totalSownArea }}</td>
            </tr>
            <tr>
              <td colspan="4">土壤质地</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NRadioGroup v-model:value="model.soilTexture">
                  <NRadio v-for="item in soilTexture" :key="item.value" :value="item.value" :label="item.label" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ getsoilTexture.get(model.soilTexture) }}</td>
            </tr>
            <tr>
              <td colspan="4">平均降雨量</td>
              <td class="text-center">毫米/年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.averageRainfall" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.averageRainfall }}</td>
            </tr>
            <tr>
              <td colspan="4">日照时数</td>
              <td class="text-center">小时/年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.sunshineHours" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.sunshineHours }}</td>
            </tr>
            <tr>
              <td colspan="4">无霜期</td>
              <td class="text-center">天/年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.frostFreePeriod" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.frostFreePeriod }}</td>
            </tr>
            <tr>
              <td colspan="4">灌溉方式</td>
              <td class="text-center">天/年</td>
              <td v-if="!isView">
                <NRadioGroup v-model:value="model.irrigationMethod">
                  <NRadio v-for="item in irrigation" :key="item.value" :value="item.value" :label="item.label" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ getIrrigation.get(model.irrigationMethod) }}</td>
            </tr>
            <!-- 棚膜使用回收情况 -->

            <!-- 工作开展情况 -->
            <template v-for="(row, index) in model.dmResidualDetails" :key="index">
              <tr>
                <td v-if="index === 0" :rowspan="model.dmResidualDetails.length * 4 + 9">地膜使用情况</td>
                <td v-if="index === 0" :rowspan="model.dmResidualDetails.length * 4">作物用膜情况(超过3茬请另行记录)</td>
                <td rowspan="4">
                  <div>第{{ index + 1 }}茬</div>
                  <div v-if="!isView">
                    <NSpace>
                      <NButton ghost circle type="primary" size="tiny" @click="plusPilot(index)">
                        <template #icon>
                          <icon-carbon:add />
                        </template>
                      </NButton>
                      <NButton v-if="model.dmResidualDetails.length > 1" ghost circle type="primary" size="tiny" @click="reducePilot(index)">
                        <template #icon>
                          <icon-carbon:close />
                        </template>
                      </NButton>
                    </NSpace>
                  </div>
                </td>
                <td colspan="2">作物名称</td>
                <td class="text-center">--</td>
                <td v-if="!isView">
                  <NInput v-model:value="row.cropName" clearable size="small" />
                </td>
                <td v-else class="text-right">{{ row.cropName }}</td>
              </tr>
              <tr>
                <td colspan="2">作物覆膜量</td>
                <td class="text-center">千克</td>
                <td v-if="!isView">
                  <NInputNumber v-model:value="row.filmQuantity" clearable :precision="2" size="small" />
                </td>
                <td v-else class="text-right">{{ row.filmQuantity }}</td>
              </tr>
              <tr>
                <td colspan="2">作物播种面积</td>
                <td class="text-center">亩</td>
                <td v-if="!isView">
                  <NInputNumber v-model:value="row.sowingArea" clearable :precision="2" size="small" />
                </td>
                <td v-else class="text-right">{{ row.sowingArea }}</td>
              </tr>
              <tr>
                <td colspan="2">作物田间覆膜比例</td>
                <td class="text-center">%</td>
                <td v-if="!isView">
                  <NInputNumber v-model:value="row.fieldCoverage" clearable :precision="2" size="small" />
                </td>
                <td v-else class="text-right">{{ row.fieldCoverage }}</td>
              </tr>
            </template>

            <tr>
              <td colspan="4">首次覆膜年份</td>
              <td class="text-center">*年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyFirstYear" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyFirstYear }}</td>
            </tr>
            <tr>
              <td colspan="4">覆膜年限</td>
              <td class="text-center">年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyCoverYears" clearable :precision="1" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyCoverYears }}</td>
            </tr>

            <tr>
              <td colspan="4">覆膜方式</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NRadioGroup v-if="!isView" v-model:value="model.dmApplyCoverMethod">
                  <NRadio :value="1" label="人工" />
                  <NRadio :value="2" label="机械" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ model.dmApplyCoverMethod == 1 ? '人工' : '机械' }}</td>
            </tr>
            <tr>
              <td colspan="4">地膜使用周期</td>
              <td class="text-center">月</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyFilmCycle" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyFilmCycle }}</td>
            </tr>
            <tr>
              <td rowspan="6">地膜产品</td>
              <td colspan="3">厂家名称</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NInput v-model:value="model.dmApplyManufacturerName" clearable size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyManufacturerName }}</td>
            </tr>
            <tr>
              <td colspan="3">厂家电话</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NInput v-model:value="model.dmApplyManufacturerTel" clearable size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyManufacturerTel }}</td>
            </tr>
            <tr>
              <td colspan="3">地膜标识厚度</td>
              <td class="text-center">毫米</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyFilmThickness" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyFilmThickness }}</td>
            </tr>
            <tr>
              <td colspan="3">地膜标识宽度</td>
              <td class="text-center">毫米</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyFilmWidth" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyFilmWidth }}</td>
            </tr>
            <tr>
              <td colspan="3">地膜颜色</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NRadioGroup v-if="!isView" v-model:value="model.dmApplyFilmColor">
                  <NRadio :value="1" label="白色" />
                  <NRadio :value="2" label="黑色" />
                  <NRadio :value="3" label="其他" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ getDmApplyFilmColor.get(model.dmApplyFilmColor) }}</td>
            </tr>
            <tr>
              <td rowspan="8">地膜回收情况</td>
            </tr>
            <tr>
              <td rowspan="7">回收方式</td>
              <td rowspan="2" colspan="2">人工捡拾</td>
              <td class="text-center">面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleManualArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleManualArea }}</td>
            </tr>
            <tr>
              <td class="text-center">成本</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleManualCost" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleManualCost }}</td>
            </tr>
            <tr>
              <td rowspan="2" colspan="2">机械回收</td>

              <td class="text-center">面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleMachineArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleMachineArea }}</td>
            </tr>
            <tr>
              <td class="text-center">成本</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleMachineCost" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleMachineCost }}</td>
            </tr>
            <tr>
              <td rowspan="2" colspan="2">复合回收（人工+机械）</td>
              <td class="text-center">面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleCompoundArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleCompoundArea }}</td>
            </tr>
            <tr>
              <td class="text-center">成本</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleCompoundCost" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleCompoundCost }}</td>
            </tr>
            <tr>
              <td colspan="2">不回收</td>
              <td class="text-center">面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleNonRecycleArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleNonRecycleArea }}</td>
            </tr>
            <tr>
              <td colspan="5">残膜回收（离田）量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleResidueAmount" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleResidueAmount }}</td>
            </tr>
            <tr>
              <td rowspan="5">残膜去向占比情况</td>
              <td colspan="4" class="text-center">堆置田头</td>
              <td class="text-center">%</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposePile" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposePile }}</td>
            </tr>
            <tr>
              <td colspan="4" class="text-center">回收利用</td>
              <td class="text-center">%</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeRecycle" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeRecycle }}</td>
            </tr>
            <tr>
              <td colspan="4" class="text-center">作为农村垃圾处理</td>
              <td class="text-center">%</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeRural" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeRural }}</td>
            </tr>

            <tr>
              <td colspan="4" class="text-center">就近焚烧</td>
              <td class="text-center">%</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeBurn" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeBurn }}</td>
            </tr>
            <tr>
              <td colspan="4" class="text-center">就近填埋</td>
              <td class="text-center">%</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeLandfill" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeLandfill }}</td>
            </tr>
            <tr>
              <td colspan="5">回收网点</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NInput v-model:value="model.dmRecycleName" clearable size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleName }}</td>
            </tr>
            <tr>
              <td colspan="5">残膜收购价格</td>
              <td class="text-center">元/千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecyclePrice" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecyclePrice }}</td>
            </tr>
            <tr>
              <td rowspan="5">各样方地膜残留状况</td>

              <td colspan="4">样方一重量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.sampleQuadratOne" clearable :precision="4" size="small" />
              </td>
              <td v-else class="text-right">{{ model.sampleQuadratOne }}</td>
            </tr>
            <tr>
              <td colspan="4">样方二重量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.sampleQuadratTwo" clearable :precision="4" size="small" />
              </td>
              <td v-else class="text-right">{{ model.sampleQuadratTwo }}</td>
            </tr>
            <tr>
              <td colspan="4">样方三重量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.sampleQuadratThree" clearable :precision="4" size="small" />
              </td>
              <td v-else class="text-right">{{ model.sampleQuadratThree }}</td>
            </tr>
            <tr>
              <td colspan="4">样方四重量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.sampleQuadratFour" clearable :precision="4" size="small" />
              </td>
              <td v-else class="text-right">{{ model.sampleQuadratFour }}</td>
            </tr>
            <tr>
              <td colspan="4">样方五重量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.sampleQuadratFive" clearable :precision="4" size="small" />
              </td>
              <td v-else class="text-right">{{ model.sampleQuadratFive }}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="foot-info">
        <NGrid v-if="!isView" x-gap="12" :cols="4">
          <NGi>
            <NInput v-model:value="model.reportPerson" :disabled="isView">
              <template #prefix>填表人姓名：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.reportPersonContactInfo" :disabled="isView">
              <template #prefix>联系电话：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.reportDate" :disabled="isView">
              <template #prefix>样方采集时间：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.reportUnit" :disabled="isView">
              <template #prefix>填报单位（公章）：</template>
            </NInput>
          </NGi>
        </NGrid>
        <NSpace v-else>
          <span class="mr-60px">
            <b>填表人姓名：</b>
            {{ model.reportPerson }}
          </span>
          <span class="mr-60px">
            <b>联系电话：</b>
            {{ model.reportPersonContactInfo }}
          </span>
          <span class="mr-60px">
            <b>样方采集时间：</b>
            {{ model.reportDate }}
          </span>
          <span>
            <b>填报单位（公章）：</b>
            {{ model.reportUnit }}
          </span>
        </NSpace>
        <div class="h-12px"></div>
        <NInput v-if="!isView" v-model:value="model.comment" type="textarea" placeholder="备注" :disabled="isView" />
        <span v-else>
          <b>备注：</b>
          {{ model.comment }}
        </span>
      </div>
    </div>
    <template #footer>
      <NSpace v-if="!isView" justify="end">
        <NButton type="warning" @click="tempSave">临时保存</NButton>
        <NButton type="error" @click="closeModal">
          {{ $t('common.cancel') }}
        </NButton>
        <NButton type="primary" @click="handleSubmit">
          {{ $t('common.save') }}
        </NButton>
      </NSpace>
    </template>
  </NModal>
</template>

<style lang="scss" scoped>
.info {
  .title-info {
    margin-bottom: 12px;
  }

  .table-info {
    table {
      width: 100%;
      border-top: 1px solid #e5e7eb;
      border-left: 1px solid #e5e7eb;
      margin-bottom: 12px;

      th,
      td {
        border-right: 1px solid #e5e7eb;
        border-bottom: 1px solid #e5e7eb;
        padding: 5px;
      }
    }
  }
}
</style>
